/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Datos;

import Entidades.Libros;
import Interfaces.ILibros;
import java.sql.Connection;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Rafael Castelo
 */
public class DBLibros implements ILibros {

    private Connection connection = new Conexion().getConection();

    @Override
    public boolean IngresarLibros(Libros dato) {
        try {
            CallableStatement statement;
            statement = connection.prepareCall("{call agregalibro (?)}");
            statement.setString(1, dato.getnombre());
            statement.executeUpdate();
        } catch (Exception ex) {
            //System.out.println("error al agregar calificaciones");
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean modificar(Libros nodo) {
        try {
            CallableStatement statement;
            statement = connection.prepareCall("{call modificalibro (?,?)}");
            statement.setString(1, nodo.getnombre());
            statement.setInt(2, nodo.getid());
            statement.executeUpdate();
        } catch (Exception ex) {
            //System.out.println("error al agregar calificaciones");
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public Libros consultalibros(String libro) {
        try{
        CallableStatement statement;
        statement=connection.prepareCall("{call consultalibro(?)}");
        statement.setString(1, libro);
        ResultSet resultset=statement.executeQuery();
        Libros nodo1=new Libros();
        nodo1.setnombre(resultset.getString(1));
        nodo1.setid(resultset.getInt(2));
        
        return nodo1;
      } catch (Exception ex) {
            //System.out.println("error al consultar");
            ex.printStackTrace();
            return null;
        }
}
    @Override
    public boolean eliminalibros(Libros dato){
        try {
            CallableStatement statement;
            statement = connection.prepareCall("{call eliminalibro (?)}");
            statement.setInt(1,dato.getid());
            statement.executeUpdate();
        } catch (Exception ex) {
            //System.out.println("error al eliminar calificacion");

            return false;
        }
        return true;
    }
    }
